package cn.lanqiao.pet;

public class Master {
    public static void main(String[] args) {
        try {
            Dog dog = new Dog("金毛"); // new 调用构造方法 -> 初始化对象
            dog.setName("旺财");
            dog.setAge(110); //数据校验
        } catch (Exception e) {
            e.printStackTrace();
        }
//        String sound = dog.bark();
//        System.out.println(sound);
//        dog.eat("骨头");
//        System.out.println(dog.getAge());
//        System.out.println(dog.getKind());

//        mouse.eat("大米");
//        System.out.println(mouse.bark());
//        Master master = new Master();
//        Dog dog = new Dog("旺财");
//        Mouse mouse = new Mouse("jerry");
//        master.feed(mouse);

//        //多态 + 非常量池
//        Object o1 = new String("david");
//        Object o2 = new String("david");
//        System.out.println(o1.equals(o2)); // String.equals()


//        Object dog1 = new Dog("dog1");
//        Object dog2 = dog1; //赋值 栈内地址的拷贝
//        System.out.println(dog1.equals(dog2));// object.equals()
//        System.out.println(dog1);  // 多态
    }

//    public void feed(Pet pet) {
//        //喂养宠物
//        String sound = pet.bark();
//        System.out.println(sound);
//
//        if (pet instanceof Dog) {
//            pet.eat("骨头");
//        } else {
//            pet.eat("大米");
//        }
//
//    }

    public void feed(Dog dog) {
        String sound = dog.bark();
        System.out.println(sound);
        dog.eat("骨头");
    }

    public void feed(Mouse mouse) {
        String sound = mouse.bark();
        System.out.println(sound);
        mouse.eat("大米");
    }
}
